﻿using System;
using System.Data;
using System.Web.UI;
using BLL;
using ET;
using Ext.Net;
using Roles;

namespace ERP.Modules
{
    public partial class Proposed_Export : UserControl
    {
        private readonly Proposed_Export_BLL clsProposedExport = new Proposed_Export_BLL();
        private readonly Export_BLL clsExport = new Export_BLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                CheckPermisstion();
                GetData();
                ClearTextBox();
            }
        }
        #region Event

        #region Event Main
        protected void btnAddNew_Click(object sender, DirectEventArgs e)
        {
            ClearTextBox();
            GetProposed_Export_Materials_Edit(0);
            WindowsProposed_Export.Show();
        }
        protected void btnEdit_Click(object sender, DirectEventArgs e)
        {
            var sm = grProposed_Export.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
                foreach (SelectedRow row in sm.SelectedRows)
                {
                    ClearTextBox();
                    DataDetail(int.Parse(row.RecordID));
                    GetProposed_Export_Materials_Edit(int.Parse(row.RecordID));
                    WindowsProposed_Export.Show();
                    sm.UpdateSelection();
                }
        }
        protected void btnDel_Click(object sender, DirectEventArgs e)
        {
            var sm = grProposed_Export.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
                foreach (SelectedRow row in sm.SelectedRows)
                {
                    try
                    {
                        var obj = new Proposed_Export_ET {Proposed_Export_ID = int.Parse(row.RecordID)};
                        Proposed_Export_BLL.Deletetb_Proposed_Export(obj);
                        if (obj.Msg == 0)
                            HTML.clsFormat.Alert_ERROR("Lỗi", "Có chứng từ liên quan.Không thể xoá được !");
                    }
                    catch (Exception)
                    {
                        HTML.clsFormat.Alert_ERROR("Thông Báo", "Tồn tại tài liệu con, không xoá được vui lòng xoá tài liệu con trước !");
                    }
                }
            GetData();
        }
        protected void btnProposed_Export_Review_Click(object sender, DirectEventArgs e)
        {
            var sm = grProposed_Export.GetSelectionModel() as CheckboxSelectionModel;
            if (sm != null)
                foreach (SelectedRow row in sm.SelectedRows)
                {
                    GetReview(int.Parse(row.RecordID));
                    WindowProposed_ExportReview.Show();
                    sm.UpdateSelection();
                }
        }
        protected void Cell_Click(object sender, DirectEventArgs e)
        {
        }
        protected void Proposed_ExportDblClick(object sender, DirectEventArgs e)
        {
            ClearTextBox();
            int Proposed_Export_Id = int.Parse(e.ExtraParams["Proposed_Export_ID"]);
            DataDetail(Proposed_Export_Id);
            GetProposed_Export_Materials_Edit(Proposed_Export_Id);
            WindowsProposed_Export.Show();
        }
        #endregion

        #region Event Popup
        protected void btnSavePopUp_Click(object sender, DirectEventArgs e)
        {
            if (txtProposed_Export_ID.Text == string.Empty)
            {
                #region[Insert]
                try
                {
                    if (!CheckInsert())
                    {
                        var GetProposed_Export_Detail = e.ExtraParams["grProposed_Export_Detail"];

                        var dtProposed_Export_Detail = JSON.Deserialize<DataTable>(GetProposed_Export_Detail);

                        if (dtProposed_Export_Detail.Rows.Count == 0)
                        {
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng thêm sản phẩm để xuất kho !");
                        }
                        else
                        {
                            var obj = new Proposed_Export_ET
                            {
                                Proposed_Export_No = txtProposed_Export_No.Text,
                                Proposed_Export_DateBegin = DateTime.Parse(txtProposed_Export_DateBegin.Text),
                                Customer_ID = int.Parse(Customer_ID.Text),
                                Order_Sell = int.Parse(ID_Sell.Text),
                                Users_Id = int.Parse(Session["Users_Id"].ToString()),
                                Proposed_Export_TaxCode = txtProposed_Export_TaxCode.Text,
                                Proposed_Export_Descripttion = txtProposed_Export_Descripttion.Text
                            };
                            var insert = Proposed_Export_BLL.Inserttb_Proposed_Export(obj);
                            if (insert)
                            {
                                foreach (DataRow rows in dtProposed_Export_Detail.Rows)
                                {
                                    var Proposed_Export_Detail = new Proposed_Export_Detail_ET
                                    {
                                        Proposed_Export_ID = obj.Proposed_Export_ID,
                                        Sell_ID = int.Parse(rows["Sell_ID"].ToString()),
                                        Materials_ID = int.Parse(rows["Materials_ID"].ToString()),
                                        Proposed_Export_Quality = int.Parse(rows["Proposed_Export_Quality_Sell"].ToString()),
                                        Proposed_Export_Quality_Still = int.Parse(rows["Proposed_Export_Quality_Sell"].ToString())
                                    };
                                    Proposed_Export_Detail_BLL.Inserttb_Proposed_Export_Detail(Proposed_Export_Detail);
                                }
                                HTML.clsFormat.Alert_INFO("Thông Báo", "Thêm mới thành công !");
                            }
                            grProposed_Export_Detail.GetStore().RemoveAll();
                            GetData();
                            ClearTextBox();
                        }
                    }
                }
                catch (Exception ex)
                {
                    HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
                }
                #endregion
            }
            else
            {
                if (CheckUpdate())
                {
                    HTML.clsFormat.Alert_ERROR("Lỗi","Có chứng từ liên quan.Bạn không được phép thay đổi !");
                }
                else
                {
                    #region[Update]
                    if (CheckPermisstionDobclick())
                    {
                        HTML.clsFormat.Alert_ERROR("Thông Báo", "Bạn không được cấp quyền để sửa đổi !");
                    }
                    else
                    {
                        try
                        {
                            if (!CheckInsert())
                            {
                                var GetProposed_Export_Detail = e.ExtraParams["grProposed_Export_Detail"];

                                var dtProposed_Export_Detail = JSON.Deserialize<DataTable>(GetProposed_Export_Detail);

                                if (dtProposed_Export_Detail.Rows.Count == 0)
                                {
                                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Vui lòng thêm sản phẩm để xuất kho !");
                                }
                                else
                                {
                                    var obj = new Proposed_Export_ET
                                    {
                                        Proposed_Export_ID = int.Parse(txtProposed_Export_ID.Text),
                                        Proposed_Export_No = txtProposed_Export_No.Text,
                                        Proposed_Export_DateBegin = DateTime.Parse(txtProposed_Export_DateBegin.Text),
                                        Customer_ID = int.Parse(Customer_ID.Text),
                                        Order_Sell = int.Parse(ID_Sell.Text),
                                        Users_Id = int.Parse(Session["Users_Id"].ToString()),
                                        Proposed_Export_TaxCode = txtProposed_Export_TaxCode.Text,
                                        Proposed_Export_Descripttion = txtProposed_Export_Descripttion.Text
                                    };
                                    bool update = Proposed_Export_BLL.Updatetb_Proposed_Export(obj);
                                    if (update)
                                    {
                                        Proposed_Export_Detail_BLL.Deletetb_Proposed_Export_Detail_DefaultID(int.Parse(txtProposed_Export_ID.Text));
                                        foreach (DataRow rows in dtProposed_Export_Detail.Rows)
                                        {
                                            var Proposed_Export_Detail = new Proposed_Export_Detail_ET
                                            {
                                                Proposed_Export_ID = int.Parse(txtProposed_Export_ID.Text),
                                                Sell_ID = int.Parse(rows["Sell_ID"].ToString()),
                                                Materials_ID = int.Parse(rows["Materials_ID"].ToString()),
                                                Proposed_Export_Quality = int.Parse(rows["Proposed_Export_Quality_Sell"].ToString()),
                                                Proposed_Export_Quality_Still = int.Parse(rows["Proposed_Export_Quality_Sell"].ToString())
                                            };
                                            Proposed_Export_Detail_BLL.Inserttb_Proposed_Export_Detail(Proposed_Export_Detail);
                                        }
                                        WindowsProposed_Export.Close();
                                        HTML.clsFormat.Alert_INFO("Thông Báo", "Sữa thành công!");
                                        GetData();
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HTML.clsFormat.Alert_ERROR("Lỗi", ex.ToString());
                        }
                    }
                    #endregion
                }
            }
        }
        protected void btnCancelPopUp_Click(object sender, DirectEventArgs e)
        {
            WindowsProposed_Export.Close();
        }
        protected void btnOrderSell_Click(object sender, DirectEventArgs e)
        {
            cbProposed_Export.Clear();
            GetMaterialsFromSell();
            StoreProposed_Export_Materials.Reload();
            WindowProposed_Export_OrderSell_Materials.Show();
        }
        protected void UpdateMaterials_Click(object sender, DirectEventArgs e)
        {

        }

        protected void cbProposed_ExportSelectIndex_Change(object sender, DirectEventArgs e)
        {
            GetProposed_Export_Materials();
        }
        protected void btnSelectProposed_Export_Materials_Click(object sender, DirectEventArgs e)
        {
            var GetProposed_Export_Materials = e.ExtraParams["grProposed_Export_Materials"];
            var GetProposed_Export_Detail = e.ExtraParams["grProposed_Export_Detail"];

            var dtProposed_Export_Materials = JSON.Deserialize<DataTable>(GetProposed_Export_Materials);
            var dtProposed_Export_Detail = JSON.Deserialize<DataTable>(GetProposed_Export_Detail);

            foreach (DataRow rows in dtProposed_Export_Materials.Rows)
            {
                var insert = new Proposed_Export_Detail_ET
                {
                    Proposed_Export_Detail_ID = -1,
                    Proposed_Export_ID = -1,
                    Sell_ID = int.Parse(rows["ID_Sell"].ToString()),
                    Materials_ID = int.Parse(rows["Materials_Id"].ToString()),
                    Materials_Alias = rows["Materials_Alias"].ToString(),
                    Materials_Name = rows["Materials_Name"].ToString(),
                    Unit_Name = rows["Unit_Name"].ToString(),
                    Proposed_Export_Quality = int.Parse(rows["Quanlity"].ToString()),
                    Proposed_Export_Quality_Still = int.Parse(rows["Sell_Detail_Quality_Remain"].ToString()),
                    Proposed_Export_Detail_Price = float.Parse(rows["Price_Initially"].ToString()),
                    Proposed_Export_Quality_Sell = 0
                };
                var kt = true;
                if (dtProposed_Export_Detail != null && dtProposed_Export_Detail.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtProposed_Export_Detail.Rows)
                    {
                        if (insert.Materials_ID.ToString() == dr["Materials_Id"].ToString())
                        {
                            kt = false;
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Sản phẩm đã tồn tại, vui lòng cập nhật số lượng !");
                        }
                    }
                }
                if (kt)
                {
                    StoreProposed_Export_Detail.Add(insert);
                }
            }
            HTML.clsFormat.Alert_INFO("Thông báo", "Thêm sản phẩm thành công !");
            ID_Sell.Text = cbProposed_Export.SelectedItem.Value ?? string.Empty;
            abc.Text = cbProposed_Export.SelectedItem.Text;
            if (cbProposed_Export.SelectedItem.Value != null)
            {
                var clsCustomer = new Proposed_Export_BLL();
                var dtCustomer = clsCustomer.GetMaterialsFromSellWithCondition(int.Parse(cbProposed_Export.SelectedItem.Value));
                foreach (DataRow row in dtCustomer.Rows)
                {
                    Customer_ID.Text = row["Customer_ID"].ToString();
                    txtCustomerAliasProposed_Export.Text = row["Customer_Alias"].ToString();
                    txtCustomerNameProposed_Export.Text = row["Customer_Name"].ToString();
                    txtProposed_Export_TaxCode.Text = row["Customer_Contract_Tax_Code"].ToString();
                    txtAddressProposed_Export.Text = row["Customer_Address"].ToString();
                }
            }
            WindowProposed_Export_OrderSell_Materials.Hide();
            CheckboxSelectionModel2.ClearSelection();
        }
        #endregion

        #endregion

        #region Store
        protected void StoreProposed_Export_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            GetData();
            SelectBoxReview.Clear();
            txtDateBeginFillter.Text = string.Empty;
            txtDateEndFillter.Text = string.Empty;
            GridFilters1.ClearFilters();
        }
        protected void StoreProposed_Export_Detail_RefreshData(object sender, StoreReadDataEventArgs e)
        {

        }
        protected void StoreProposed_Export_Materials_RefreshData(object sender, StoreReadDataEventArgs e)
        {

        }
        protected void StoreOrderSell_Detail_RefreshData(object sender, StoreReadDataEventArgs e)
        {

        }
        #endregion

        #region Method
        private void GetData()
        {
            var dtGetProposed_Export = clsProposedExport.BindGirdtb_Proposed_Export(txtSearch.Text);
            if (dtGetProposed_Export != null && dtGetProposed_Export.Rows.Count > 0)
            {
                StoreProposed_Export.DataSource = dtGetProposed_Export;
                StoreProposed_Export.DataBind();
            }
            else
            {
                grProposed_Export.GetStore().RemoveAll();
            }
        }
        protected void DataDetail(int id)
        {
            DataTable dtProposed_Export = clsProposedExport.BindGirdtb_Proposed_ExportDetail(id);
            if (dtProposed_Export != null && dtProposed_Export.Rows.Count > 0)
            {
                txtProposed_Export_ID.Text = dtProposed_Export.Rows[0]["Proposed_Export_ID"].ToString();
                txtProposed_Export_No.Text = dtProposed_Export.Rows[0]["Proposed_Export_No"].ToString();
                ID_Sell.Text = dtProposed_Export.Rows[0]["Order_Sell"].ToString();
                abc.Text = dtProposed_Export.Rows[0]["Sell_Code"].ToString();
                txtProposed_Export_DateBegin.Text = dtProposed_Export.Rows[0]["Proposed_Export_DateBegin"].ToString();
                Customer_ID.Text = dtProposed_Export.Rows[0]["Customer_ID"].ToString();
                txtCustomerAliasProposed_Export.Text = dtProposed_Export.Rows[0]["Customer_Alias"].ToString();
                txtCustomerNameProposed_Export.Text = dtProposed_Export.Rows[0]["Customer_Name"].ToString();
                txtProposed_Export_TaxCode.Text = dtProposed_Export.Rows[0]["Proposed_Export_TaxCode"].ToString();
                txtAddressProposed_Export.Text = dtProposed_Export.Rows[0]["Customer_Address"].ToString();
                txtProposed_Export_Descripttion.Text = dtProposed_Export.Rows[0]["Proposed_Export_Descripttion"].ToString();
                if ((bool)dtProposed_Export.Rows[0]["IsActive"])
                {
                    btnSavePopUp.Disable(true);
                }
                else
                {
                    btnSavePopUp.Enable(true);
                }
            }
        }
        private void GetMaterialsFromSell()
        {
            var Proposed_Export_BLL = new Proposed_Export_BLL();
            var dt = Proposed_Export_BLL.GetMaterialsFromSell();
            if (dt != null && dt.Rows.Count > 0)
            {
                Proposed_ExportStore.DataSource = dt;
                Proposed_ExportStore.DataBind();
            }
            else
            {
                grProposed_Export.GetStore().RemoveAll();
            }
        }
        protected void GetProposed_Export_Materials()
        {
            var clsProposed_Export = new Proposed_Export_BLL();
            if (cbProposed_Export.SelectedItem.Value != null)
            {
                grProposed_Export_Detail.GetStore().RemoveAll();
                DataTable dtGetMaterialProposed_Export = clsProposed_Export.GetMaterialsFromSellWithCondition(int.Parse(cbProposed_Export.SelectedItem.Value));
                if (dtGetMaterialProposed_Export != null && dtGetMaterialProposed_Export.Rows.Count > 0)
                {
                    StoreProposed_Export_Materials.DataSource = dtGetMaterialProposed_Export;
                    StoreProposed_Export_Materials.DataBind();
                }
                else
                {
                    grProposed_Export_Materials.GetStore().RemoveAll();
                }
            }
            else
            {
                grProposed_Export_Detail.GetStore().RemoveAll();
                grProposed_Export_Materials.GetStore().RemoveAll();
            }
        }
        private void GetDataProposed_Export_FilterDate()
        {
            var dtGetProposed_Export = clsProposedExport.FilterDate_Proposed_Export(txtDateBeginFillter.Text, txtDateEndFillter.Text);
            if (dtGetProposed_Export != null && dtGetProposed_Export.Rows.Count > 0)
            {
                StoreProposed_Export.DataSource = dtGetProposed_Export;
                StoreProposed_Export.DataBind();
            }
            else
            {
                grProposed_Export.GetStore().RemoveAll();
            }
        }
        private void GetProposed_Export_Materials_Edit(int proposedExportId)
        {
            var clsProposed_Export_Materials = new Proposed_Export_Detail_BLL();
            DataTable dtProposed_Export_Materials = clsProposed_Export_Materials.BindGirdtb_Proposed_Export_Detail_Edit(proposedExportId);
            if (dtProposed_Export_Materials != null)
            {
                StoreProposed_Export_Detail.DataSource = dtProposed_Export_Materials;
                StoreProposed_Export_Detail.DataBind();
            }
        }
        protected bool CheckInsert()
        {
            bool kiemtra = false;
            var dtProposed_Export = clsProposedExport.BindGirdtb_Proposed_Export(string.Empty);
            if (dtProposed_Export != null && dtProposed_Export.Rows.Count > 0)
            {
                foreach (DataRow dr in dtProposed_Export.Rows)
                {
                    if (txtProposed_Export_ID.Text != dr["Proposed_Export_ID"].ToString())
                    {
                        if (txtProposed_Export_No.Text == dr["Proposed_Export_No"].ToString())
                        {
                            kiemtra = true;
                            HTML.clsFormat.Alert_ERROR("Thông Báo", "Mã nhập kho đã tồn tại !");
                        }
                    }
                }
            }
            return kiemtra;
        }
        protected bool CheckUpdate()
        {
            bool kiemtra = false;
            var dtProposed_Export = clsExport.BindGirdtb_Export(string.Empty);
            if (dtProposed_Export != null && dtProposed_Export.Rows.Count > 0)
            {
                foreach (DataRow dr in dtProposed_Export.Rows)
                {
                    if (txtReviewProposed_Export_ID.Text == dr["Proposed_Export_ID"].ToString())
                    {
                        kiemtra = true;
                    }
                }
            }
            return kiemtra;
        }
        #endregion

        #region Unknown
        protected void ReloadComboBox(object sender, StoreReadDataEventArgs e)
        {
            cbProposed_Export.Clear();
            GetMaterialsFromSell();
            StoreProposed_Export_Materials.Reload();
        }
        protected void BranchSelectIndex_Change(object sender, StoreReadDataEventArgs e)
        {

        }
        protected void WarehouseSelectIndex_Change(object sender, StoreReadDataEventArgs e)
        {

        }
        #endregion

        #region[ClearTextbox]
        protected void ClearTextBox()
        {
            FormPanelProposed_Export.Reset();

            txtProposed_Export_ID.Text = string.Empty;
            txtProposed_Export_No.Text = MaTuDong();
            txtProposed_Export_DateBegin.Text = DateTime.Now.ToString();
        }
        #endregion

        #region[MaTangTuDong]
        protected string MaTuDong()
        {
            int i;
            var dt = clsProposedExport.BindGirdtb_Proposed_Export(string.Empty);
            if (dt != null && dt.Rows.Count > 0)
            {
                int max = int.Parse(dt.Rows[0]["Proposed_Export_ID"].ToString());
                for (i = 0; i < dt.Rows.Count; i++)
                {
                    if (int.Parse(dt.Rows[i]["Proposed_Export_ID"].ToString()) > max)
                    {
                        max = int.Parse(dt.Rows[i]["Proposed_Export_ID"].ToString());
                    }
                }
                i = max + 1;
            }
            else
            {
                i = 0;
            }
            return "PĐN_" + DateTime.Now.Day + DateTime.Now.Month + "_00" + i;
        }
        #endregion

        #region [Search-Filter]
        protected void Search_Event(object sender, DirectEventArgs e)
        {
            GetData();
        }
        protected void btnFillter_Click(object sender, DirectEventArgs e)
        {
            GetDataProposed_Export_FilterDate();
        }
        protected void SetFilter(object sender, DirectEventArgs e)
        {
            var sf = (BooleanFilter)GridFilters1.Filters[0];
            sf.SetValue(SelectBoxReview.SelectedItem.Value == "true");
            sf.SetActive(true);
        }
        protected void SearchMaterial_Event(object sender, DirectEventArgs e)
        {

        }
        #endregion

        #region[Permisstion]
        private void CheckPermisstion()
        {
            if (Session["login"] != null && Session["USer_Detail_Id"].ToString() != string.Empty)
            {
                bool Is_BtnAdd;
                bool Is_BtnEdit;
                bool Is_BtnView;
                bool Is_BtnDel;
                bool Is_BtnPrint;
                bool Is_BtnCancel;
                bool Is_BtnReview;

                SecurityServices.HasPermisstion_Btn(StringContent.Proposed_Export, out Is_BtnAdd, out Is_BtnEdit, out Is_BtnDel, out Is_BtnView, out Is_BtnCancel, out Is_BtnPrint, out Is_BtnReview);
                if (Is_BtnAdd == false)
                {
                    btnAddNew.Visible = false;
                }
                if (Is_BtnEdit == false)
                {
                    btnEdit.Visible = false;
                }
                if (Is_BtnView == false)
                {
                    PanelProposed_Export.Visible = false;
                }
                if (Is_BtnDel == false)
                {
                    btnDel.Visible = false;
                }
                if (Is_BtnPrint == false)
                {
                    btnExport.Visible = false;
                }
            }
        }
        private bool CheckPermisstionDobclick()
        {
            var check = false;
            if (Session["login"] != null && Session["USer_Detail_Id"].ToString() != string.Empty)
            {
                bool Is_BtnAdd;
                bool Is_BtnEdit;
                bool Is_BtnView;
                bool Is_BtnDel;
                bool Is_BtnPrint;
                bool Is_BtnCancel;
                bool Is_BtnReview;

                SecurityServices.HasPermisstion_Btn(StringContent.Proposed_Export, out Is_BtnAdd, out Is_BtnEdit, out Is_BtnDel, out Is_BtnView, out Is_BtnCancel, out Is_BtnPrint, out Is_BtnReview);
                if (Is_BtnEdit == false)
                {
                    check = true;
                }
            }
            return check;
        }
        #endregion

        #region [Review]
        protected void btnReviewWindow_Click(object sender, DirectEventArgs e)
        {
            if (CheckUpdate())
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", "Có chứng từ liên quan.Bạn không thể thay đổi trạng thái duyệt !");
            }
            else
            {
                ReView();
            }
        }
        protected void btnUnReviewWindow_Click(object sender, DirectEventArgs e)
        {
            if (CheckUpdate())
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", "Có chứng từ liên quan.Bạn không thể thay đổi trạng thái duyệt !");
            }
            else
            {
                UnReView();
            }
        }
        protected void StoreReview_RefreshData(object sender, StoreReadDataEventArgs e)
        {
            var clsReview = new Proposed_Export_Detail_BLL();
            StoreReview.DataSource = clsReview.BindGirdtb_Proposed_Export_Detail_Edit(int.Parse(txtReviewProposed_Export_ID.Text));
            StoreReview.DataBind();
        }
        private void GetReview(int proposedExportId)
        {
            DataTable dtProposed_Export = clsProposedExport.BindGirdtb_Proposed_ExportDetail(proposedExportId);
            if (dtProposed_Export != null && dtProposed_Export.Rows.Count > 0)
            {
                txtReviewProposed_Export_ID.Text = dtProposed_Export.Rows[0]["Proposed_Export_ID"].ToString();
                lbReviewCustomer_Alias.Text = dtProposed_Export.Rows[0]["Customer_Alias"].ToString();
                lbReviewCustomer_Name.Text = dtProposed_Export.Rows[0]["Customer_Name"].ToString();
                lbReviewOrderCode.Text = dtProposed_Export.Rows[0]["Proposed_Export_No"].ToString();
                lbReviewOrderDate.Text = String.Format("{0:dd-MM-yyyy}",dtProposed_Export.Rows[0]["Proposed_Export_DateBegin"]);
                lbReviewDateUpdate.Text = String.Format("{0:dd-MM-yyyy}",dtProposed_Export.Rows[0]["Proposed_Export_DateRespone"]);
                lbReViewTime.Text = String.Format("{0:HH:mm:ss}", dtProposed_Export.Rows[0]["Proposed_Export_DateRespone"]);
                if ((bool)dtProposed_Export.Rows[0]["IsActive"])
                {
                    lbReViewTime.IconCls = "x-icon-tick";
                    lbReviewDateUpdate.IconCls = "x-icon-tick";
                    btnReviewWindow.Disable(true);
                    btnUnReviewWindow.Enable(true);

                }
                if ((bool)dtProposed_Export.Rows[0]["IsActive"] == false)
                {
                    lbReViewTime.IconCls = "x-icon-cross";
                    lbReviewDateUpdate.IconCls = "x-icon-cross";
                    btnReviewWindow.Enable(true);
                    btnUnReviewWindow.Disable(true);
                }
            }

            var clsReview = new Proposed_Export_Detail_BLL();
            StoreReview.DataSource = clsReview.BindGirdtb_Proposed_Export_Detail_Edit(proposedExportId);
            StoreReview.DataBind();
        }
        private void ReView()
        {
            try
            {
                var obj = new Proposed_Export_ET
                {
                    Proposed_Export_ID = int.Parse(txtReviewProposed_Export_ID.Text),
                    Users_Id_Respone = int.Parse(Session["Users_Id"].ToString()),
                    IsActive = true
                };
                Proposed_Export_BLL.Review(obj);
                if (obj.Msg == 0)
                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Phiếu đề nghị nhập kho này đã được phê duyệt !");
                else
                    HTML.clsFormat.Alert_INFO("Thông Báo", "Xét duyệt phiếu đề nghị xuất kho thành công !");
                GetReview(int.Parse(txtReviewProposed_Export_ID.Text));
                GetData();
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        private void UnReView()
        {
            try
            {
                var obj = new Proposed_Export_ET
                {
                    Proposed_Export_ID = int.Parse(txtReviewProposed_Export_ID.Text),
                    Users_Id_Respone = int.Parse(Session["Users_Id"].ToString()),
                    IsActive = false
                };
                Proposed_Export_BLL.UnReview(obj);
                if (obj.Msg == 0)
                    HTML.clsFormat.Alert_ERROR("Thông Báo", "Phiếu đặt hàng này đã từ chối !");
                else
                    HTML.clsFormat.Alert_INFO("Thông Báo", "Bỏ duyệt phiếu đặt hàng thành công !");
                GetReview(int.Parse(txtReviewProposed_Export_ID.Text));
                GetData();
            }
            catch (Exception ex)
            {
                HTML.clsFormat.Alert_ERROR("Lỗi", ex.Message);
            }
        }
        #endregion
    }
}